<?php

namespace Yolo\Components\RpcClient\Annotations;

use Attribute;
use Yolo\Components\RpcClient\ClientInterface;
use Yolo\Components\RpcClient\ClientManager;
use Yolo\Di\DI;
use Yolo\Di\PropertyAttributeInterface;

#[Attribute(Attribute::TARGET_PARAMETER | Attribute::TARGET_PROPERTY)]
class RpcClient implements PropertyAttributeInterface
{
    public function __construct(private readonly string $serviceName)
    {
    }

    public function inject(): ClientInterface
    {
        $manager = DI::use(ClientManager::class);
        return $manager->getClient($this->serviceName);
    }
}
